/******************************************************************************
 * Arquivo: DistanciaComparator.java                                                           *
 * Autor: Aurindo Jorge Ferreira                                              *
 * e-mail: aurindo@gmail.com                                                  *
 * Data de cria��o: 09/12/2007                                                   *
 *                                                                            *
 * Propriedade de FastFind Solu��es Tecnologicas                              *
 ******************************************************************************/

package br.com.srv.util;

import java.util.Comparator;
import java.util.Map;

@SuppressWarnings("unchecked")
public class DistanciaComparator implements Comparator {
	
	
	@SuppressWarnings({ "unchecked", "unchecked" })
	public int compare(Object map1, Object map2) {
		
		int returnValue = 0;
 
 		if( map1 == null || map2 == null ) {
 			if( map1 == null && map2 == null )
 				returnValue = 0;
 			else if( map1 == null )
 				returnValue = -1;
 			else if( map2 == null )
 				returnValue = 1;
 
 			returnValue = 0;
 		} else {
 			
 			Double value1 = new Double(((Map<String, String>)map1).get("DISTANCIA").toString());
 			Double value2 = new Double(((Map<String, String>)map2).get("DISTANCIA").toString());	

 			if (value1 != null && value2 != null) {
 				returnValue = value1.compareTo(value2);
 			}
 		}

		return returnValue;
	}

}
